using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections;

using Thinktecture.Tools.Web.Services.Wscf.Environment;

namespace Thinktecture.Tools.Web.Services.ContractFirst
{
	/// <summary>
	/// Summary description for WebServiceCodeGenOptions.
	/// </summary>
	public class WebServiceCodeGenDialogNew : Form
	{
		private Button button1;
		private Button button2;
		private GroupBox groupBox2;
		private Label label1;
		private TextBox tbProxyFile;
		private Label label2;
		private Label label3;
		private TextBox tbStubFile;
		private Label label6;
		private TextBox tbNamespaceProxy;
		private TextBox tbNamespaceStub;
		private ToolTip cfTooltip;
		private Panel panel1;
		private GroupBox groupBox5;
		private Label label4;
		private Button bnBrowse;
		private OpenFileDialog openFileDialogWSDL;
		private IContainer components;

		private bool externalFile = false;
		private string wsdlLocation = "";
		private string wsdlPath = "";
		private CheckBox cbSettings;
		private CheckBox cbSeperateFiles;
		private PictureBox pbWizard;
		private ComboBox cbWsdlLocation;
		private System.Windows.Forms.CheckBox cbOverwrite;
		private System.Windows.Forms.PictureBox pbWscf;
		private System.Windows.Forms.CheckBox cbAdjustCasing;
		private System.Windows.Forms.CheckBox cbMultipleFiles;
		private System.Windows.Forms.GroupBox groupBox6;
		private System.Windows.Forms.CheckBox cbEndpointConfig;
		private System.Windows.Forms.CheckBox cbAccessSOAP;
		private System.Windows.Forms.CheckBox cbCollections;
		private System.Windows.Forms.CheckBox cbSerializable;
		private System.Windows.Forms.GroupBox groupBox7;
		private System.Windows.Forms.CheckBox cbEnableWsdl;
		private System.Windows.Forms.CheckBox cbValidate;
		private System.Windows.Forms.CheckBox cbProperties;
		private System.Windows.Forms.RadioButton rbServer;
		private System.Windows.Forms.RadioButton rbClient;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox4;
        private CheckBox cbOrderIds;
        private CheckBox cbOldAsync;
        private CheckBox cbDataBinding;
		private ArrayList wsdlFileCache;
        private CheckBox cbXxxSpecified;
        private CheckBox cbGenericList;
        private bool isLoading = true;

		public WebServiceCodeGenDialogNew()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			
			// Initialize the .wsdl file cache.
			wsdlFileCache = new ArrayList();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WebServiceCodeGenDialogNew));
            this.cbSeperateFiles = new System.Windows.Forms.CheckBox();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.tbNamespaceProxy = new System.Windows.Forms.TextBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.tbNamespaceStub = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.tbStubFile = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.tbProxyFile = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.cfTooltip = new System.Windows.Forms.ToolTip(this.components);
            this.cbSettings = new System.Windows.Forms.CheckBox();
            this.pbWscf = new System.Windows.Forms.PictureBox();
            this.cbAdjustCasing = new System.Windows.Forms.CheckBox();
            this.cbMultipleFiles = new System.Windows.Forms.CheckBox();
            this.cbEndpointConfig = new System.Windows.Forms.CheckBox();
            this.cbAccessSOAP = new System.Windows.Forms.CheckBox();
            this.cbCollections = new System.Windows.Forms.CheckBox();
            this.cbSerializable = new System.Windows.Forms.CheckBox();
            this.cbEnableWsdl = new System.Windows.Forms.CheckBox();
            this.cbValidate = new System.Windows.Forms.CheckBox();
            this.cbProperties = new System.Windows.Forms.CheckBox();
            this.rbServer = new System.Windows.Forms.RadioButton();
            this.rbClient = new System.Windows.Forms.RadioButton();
            this.cbOverwrite = new System.Windows.Forms.CheckBox();
            this.cbOldAsync = new System.Windows.Forms.CheckBox();
            this.cbDataBinding = new System.Windows.Forms.CheckBox();
            this.cbOrderIds = new System.Windows.Forms.CheckBox();
            this.cbGenericList = new System.Windows.Forms.CheckBox();
            this.cbXxxSpecified = new System.Windows.Forms.CheckBox();
            this.panel1 = new System.Windows.Forms.Panel();
            this.pbWizard = new System.Windows.Forms.PictureBox();
            this.groupBox5 = new System.Windows.Forms.GroupBox();
            this.cbWsdlLocation = new System.Windows.Forms.ComboBox();
            this.bnBrowse = new System.Windows.Forms.Button();
            this.label4 = new System.Windows.Forms.Label();
            this.openFileDialogWSDL = new System.Windows.Forms.OpenFileDialog();
            this.groupBox6 = new System.Windows.Forms.GroupBox();
            this.groupBox7 = new System.Windows.Forms.GroupBox();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox4 = new System.Windows.Forms.GroupBox();
            this.groupBox2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pbWscf)).BeginInit();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pbWizard)).BeginInit();
            this.groupBox5.SuspendLayout();
            this.groupBox6.SuspendLayout();
            this.groupBox7.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.groupBox4.SuspendLayout();
            this.SuspendLayout();
            // 
            // cbSeperateFiles
            // 
            this.cbSeperateFiles.Location = new System.Drawing.Point(0, 0);
            this.cbSeperateFiles.Name = "cbSeperateFiles";
            this.cbSeperateFiles.Size = new System.Drawing.Size(104, 24);
            this.cbSeperateFiles.TabIndex = 0;
            this.cfTooltip.SetToolTip(this.cbSeperateFiles, "Generates collection-based members instead of arrays.");
            // 
            // button1
            // 
            this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.button1.DialogResult = System.Windows.Forms.DialogResult.Retry;
            this.button1.Enabled = false;
            this.button1.Location = new System.Drawing.Point(387, 407);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(77, 28);
            this.button1.TabIndex = 24;
            this.button1.Text = "Generate";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.button2.Location = new System.Drawing.Point(484, 407);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(77, 28);
            this.button2.TabIndex = 25;
            this.button2.Text = "Cancel";
            // 
            // tbNamespaceProxy
            // 
            this.tbNamespaceProxy.Enabled = false;
            this.tbNamespaceProxy.Location = new System.Drawing.Point(104, 50);
            this.tbNamespaceProxy.Name = "tbNamespaceProxy";
            this.tbNamespaceProxy.Size = new System.Drawing.Size(160, 20);
            this.tbNamespaceProxy.TabIndex = 19;
            this.cfTooltip.SetToolTip(this.tbNamespaceProxy, "Please enter the name of .NET namespace for the client proxy.");
            // 
            // groupBox2
            // 
            this.groupBox2.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.groupBox2.Controls.Add(this.tbNamespaceProxy);
            this.groupBox2.Controls.Add(this.tbNamespaceStub);
            this.groupBox2.Controls.Add(this.label6);
            this.groupBox2.Controls.Add(this.tbStubFile);
            this.groupBox2.Controls.Add(this.label3);
            this.groupBox2.Controls.Add(this.label2);
            this.groupBox2.Controls.Add(this.tbProxyFile);
            this.groupBox2.Controls.Add(this.label1);
            this.groupBox2.Location = new System.Drawing.Point(8, 318);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(553, 80);
            this.groupBox2.TabIndex = 8;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Files and namespaces  ";
            // 
            // tbNamespaceStub
            // 
            this.tbNamespaceStub.Enabled = false;
            this.tbNamespaceStub.Location = new System.Drawing.Point(379, 50);
            this.tbNamespaceStub.Name = "tbNamespaceStub";
            this.tbNamespaceStub.Size = new System.Drawing.Size(165, 20);
            this.tbNamespaceStub.TabIndex = 21;
            this.cfTooltip.SetToolTip(this.tbNamespaceStub, "Please enter the name of .NET namespace for the service code.");
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(275, 52);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(112, 16);
            this.label6.TabIndex = 16;
            this.label6.Text = "Service namespace:";
            // 
            // tbStubFile
            // 
            this.tbStubFile.Enabled = false;
            this.tbStubFile.Location = new System.Drawing.Point(379, 24);
            this.tbStubFile.Name = "tbStubFile";
            this.tbStubFile.Size = new System.Drawing.Size(165, 20);
            this.tbStubFile.TabIndex = 20;
            this.cfTooltip.SetToolTip(this.tbStubFile, "Please enter the name of .NET service facade file that gets generated.");
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(275, 26);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(96, 16);
            this.label3.TabIndex = 11;
            this.label3.Text = "Service filename:";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(8, 26);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(88, 16);
            this.label2.TabIndex = 10;
            this.label2.Text = "Proxy filename:";
            // 
            // tbProxyFile
            // 
            this.tbProxyFile.Enabled = false;
            this.tbProxyFile.Location = new System.Drawing.Point(104, 24);
            this.tbProxyFile.Name = "tbProxyFile";
            this.tbProxyFile.Size = new System.Drawing.Size(160, 20);
            this.tbProxyFile.TabIndex = 18;
            this.cfTooltip.SetToolTip(this.tbProxyFile, "Please enter the name of .NET proxy file that gets generated.");
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8, 52);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(104, 16);
            this.label1.TabIndex = 8;
            this.label1.Text = "Proxy namespace:";
            // 
            // cbSettings
            // 
            this.cbSettings.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.cbSettings.Location = new System.Drawing.Point(10, 411);
            this.cbSettings.Name = "cbSettings";
            this.cbSettings.Size = new System.Drawing.Size(128, 23);
            this.cbSettings.TabIndex = 22;
            this.cbSettings.Text = "Remember settings";
            this.cfTooltip.SetToolTip(this.cbSettings, "Save dialog settings for future use.");
            this.cbSettings.CheckedChanged += new System.EventHandler(this.cbSettings_CheckedChanged);
            // 
            // pbWscf
            // 
            this.pbWscf.Image = ((System.Drawing.Image)(resources.GetObject("pbWscf.Image")));
            this.pbWscf.Location = new System.Drawing.Point(462, 4);
            this.pbWscf.Name = "pbWscf";
            this.pbWscf.Size = new System.Drawing.Size(104, 32);
            this.pbWscf.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pbWscf.TabIndex = 11;
            this.pbWscf.TabStop = false;
            this.cfTooltip.SetToolTip(this.pbWscf, "http://www.thinktecture.com/");
            this.pbWscf.Click += new System.EventHandler(this.pbWscf_Click);
            // 
            // cbAdjustCasing
            // 
            this.cbAdjustCasing.Location = new System.Drawing.Point(16, 94);
            this.cbAdjustCasing.Name = "cbAdjustCasing";
            this.cbAdjustCasing.Size = new System.Drawing.Size(102, 24);
            this.cbAdjustCasing.TabIndex = 16;
            this.cbAdjustCasing.Text = "Adjust casing";
            this.cfTooltip.SetToolTip(this.cbAdjustCasing, "Ensures that generated .NET types follow the .NET guidelines for casing.");
            // 
            // cbMultipleFiles
            // 
            this.cbMultipleFiles.Location = new System.Drawing.Point(425, 58);
            this.cbMultipleFiles.Name = "cbMultipleFiles";
            this.cbMultipleFiles.Size = new System.Drawing.Size(96, 24);
            this.cbMultipleFiles.TabIndex = 15;
            this.cbMultipleFiles.Text = "Separate files";
            this.cfTooltip.SetToolTip(this.cbMultipleFiles, "Generates each data type into its own seperate source file.");
            // 
            // cbEndpointConfig
            // 
            this.cbEndpointConfig.Enabled = false;
            this.cbEndpointConfig.Location = new System.Drawing.Point(16, 24);
            this.cbEndpointConfig.Name = "cbEndpointConfig";
            this.cbEndpointConfig.Size = new System.Drawing.Size(120, 24);
            this.cbEndpointConfig.TabIndex = 3;
            this.cbEndpointConfig.Text = "Configure endpoint";
            this.cfTooltip.SetToolTip(this.cbEndpointConfig, "Enable Web Service endpoint configuration in a .config file.");
            // 
            // cbAccessSOAP
            // 
            this.cbAccessSOAP.Enabled = false;
            this.cbAccessSOAP.Location = new System.Drawing.Point(145, 24);
            this.cbAccessSOAP.Name = "cbAccessSOAP";
            this.cbAccessSOAP.Size = new System.Drawing.Size(120, 23);
            this.cbAccessSOAP.TabIndex = 4;
            this.cbAccessSOAP.Text = "Access messages";
            this.cfTooltip.SetToolTip(this.cbAccessSOAP, "Enable read-only access to the actual SOAP message in client code.");
            // 
            // cbCollections
            // 
            this.cbCollections.Location = new System.Drawing.Point(299, 23);
            this.cbCollections.Name = "cbCollections";
            this.cbCollections.Size = new System.Drawing.Size(80, 24);
            this.cbCollections.TabIndex = 10;
            this.cbCollections.Text = "Collections";
            this.cfTooltip.SetToolTip(this.cbCollections, "Generates collection-based members instead of arrays.");
            this.cbCollections.CheckedChanged += new System.EventHandler(this.cbCollections_CheckedChanged);
            // 
            // cbSerializable
            // 
            this.cbSerializable.Location = new System.Drawing.Point(144, 25);
            this.cbSerializable.Name = "cbSerializable";
            this.cbSerializable.Size = new System.Drawing.Size(128, 20);
            this.cbSerializable.TabIndex = 9;
            this.cbSerializable.Text = "Serializable classes";
            this.cfTooltip.SetToolTip(this.cbSerializable, "Generate runtime serializable data classes.");
            // 
            // cbEnableWsdl
            // 
            this.cbEnableWsdl.Enabled = false;
            this.cbEnableWsdl.Location = new System.Drawing.Point(16, 24);
            this.cbEnableWsdl.Name = "cbEnableWsdl";
            this.cbEnableWsdl.Size = new System.Drawing.Size(96, 24);
            this.cbEnableWsdl.TabIndex = 6;
            this.cbEnableWsdl.Text = "Enable WSDL";
            this.cfTooltip.SetToolTip(this.cbEnableWsdl, "Enable ?wsdl for return WSDL from the endpoint");
            // 
            // cbValidate
            // 
            this.cbValidate.Enabled = false;
            this.cbValidate.Location = new System.Drawing.Point(127, 24);
            this.cbValidate.Name = "cbValidate";
            this.cbValidate.Size = new System.Drawing.Size(120, 24);
            this.cbValidate.TabIndex = 7;
            this.cbValidate.Text = "Validate messages";
            this.cfTooltip.SetToolTip(this.cbValidate, "Enable XSD-based validation on incoming SOAP messages");
            // 
            // cbProperties
            // 
            this.cbProperties.Location = new System.Drawing.Point(16, 24);
            this.cbProperties.Name = "cbProperties";
            this.cbProperties.Size = new System.Drawing.Size(115, 23);
            this.cbProperties.TabIndex = 8;
            this.cbProperties.Text = "Public properties";
            this.cfTooltip.SetToolTip(this.cbProperties, "Generate public properties in your data classes instead of public fields.");
            // 
            // rbServer
            // 
            this.rbServer.Location = new System.Drawing.Point(9, -4);
            this.rbServer.Name = "rbServer";
            this.rbServer.Size = new System.Drawing.Size(112, 24);
            this.rbServer.TabIndex = 5;
            this.rbServer.Text = "Service-side stub";
            this.cfTooltip.SetToolTip(this.rbServer, "Select this to generate the service-side stub");
            this.rbServer.CheckedChanged += new System.EventHandler(this.cbServer_CheckedChanged);
            // 
            // rbClient
            // 
            this.rbClient.Location = new System.Drawing.Point(9, -4);
            this.rbClient.Name = "rbClient";
            this.rbClient.Size = new System.Drawing.Size(111, 24);
            this.rbClient.TabIndex = 2;
            this.rbClient.Text = "Client-side proxy";
            this.cfTooltip.SetToolTip(this.rbClient, "Select this to generate the client-side proxy");
            this.rbClient.CheckedChanged += new System.EventHandler(this.cbClient_CheckedChanged);
            // 
            // cbOverwrite
            // 
            this.cbOverwrite.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.cbOverwrite.Location = new System.Drawing.Point(136, 410);
            this.cbOverwrite.Name = "cbOverwrite";
            this.cbOverwrite.Size = new System.Drawing.Size(144, 24);
            this.cbOverwrite.TabIndex = 23;
            this.cbOverwrite.Text = "Overwrite existing files";
            this.cfTooltip.SetToolTip(this.cbOverwrite, "Overwrite all files upon code generation.");
            this.cbOverwrite.CheckedChanged += new System.EventHandler(this.cbOverwrite_CheckedChanged);
            // 
            // cbOldAsync
            // 
            this.cbOldAsync.AutoSize = true;
            this.cbOldAsync.Location = new System.Drawing.Point(299, 62);
            this.cbOldAsync.Name = "cbOldAsync";
            this.cbOldAsync.Size = new System.Drawing.Size(100, 17);
            this.cbOldAsync.TabIndex = 14;
            this.cbOldAsync.Text = "Old async code";
            this.cfTooltip.SetToolTip(this.cbOldAsync, "Creates Begin and End methods for the asynchronous invocation of Web Services.");
            this.cbOldAsync.UseVisualStyleBackColor = true;
            // 
            // cbDataBinding
            // 
            this.cbDataBinding.AutoSize = true;
            this.cbDataBinding.Location = new System.Drawing.Point(16, 62);
            this.cbDataBinding.Name = "cbDataBinding";
            this.cbDataBinding.Size = new System.Drawing.Size(86, 17);
            this.cbDataBinding.TabIndex = 12;
            this.cbDataBinding.Text = "Data binding";
            this.cfTooltip.SetToolTip(this.cbDataBinding, "Implement INotifyPropertyChanged interface on all generated types to enable data " +
                    "binding.");
            this.cbDataBinding.UseVisualStyleBackColor = true;
            this.cbDataBinding.CheckedChanged += new System.EventHandler(this.cbDataBinding_CheckedChanged);
            // 
            // cbOrderIds
            // 
            this.cbOrderIds.AutoSize = true;
            this.cbOrderIds.Location = new System.Drawing.Point(144, 62);
            this.cbOrderIds.Name = "cbOrderIds";
            this.cbOrderIds.Size = new System.Drawing.Size(99, 17);
            this.cbOrderIds.TabIndex = 13;
            this.cbOrderIds.Text = "Order identifiers";
            this.cfTooltip.SetToolTip(this.cbOrderIds, "Generate explicit order identifiers on particle members.");
            this.cbOrderIds.UseVisualStyleBackColor = true;
            // 
            // cbGenericList
            // 
            this.cbGenericList.AutoSize = true;
            this.cbGenericList.Location = new System.Drawing.Point(425, 27);
            this.cbGenericList.Name = "cbGenericList";
            this.cbGenericList.Size = new System.Drawing.Size(61, 17);
            this.cbGenericList.TabIndex = 11;
            this.cbGenericList.Text = "List<T>";
            this.cfTooltip.SetToolTip(this.cbGenericList, "Generates List<T>-based members instead of arrays.");
            this.cbGenericList.UseVisualStyleBackColor = true;
            this.cbGenericList.CheckedChanged += new System.EventHandler(this.cbGenericList_CheckedChanged);
            // 
            // cbXxxSpecified
            // 
            this.cbXxxSpecified.AutoSize = true;
            this.cbXxxSpecified.Location = new System.Drawing.Point(144, 98);
            this.cbXxxSpecified.Name = "cbXxxSpecified";
            this.cbXxxSpecified.Size = new System.Drawing.Size(145, 17);
            this.cbXxxSpecified.TabIndex = 17;
            this.cbXxxSpecified.Text = "No xxxSpecified handling";
            this.cfTooltip.SetToolTip(this.cbXxxSpecified, "Disable the default automatic setting of appropriate xxxSpecified fields.");
            this.cbXxxSpecified.UseVisualStyleBackColor = true;
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.Color.White;
            this.panel1.Controls.Add(this.pbWscf);
            this.panel1.Controls.Add(this.pbWizard);
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(648, 40);
            this.panel1.TabIndex = 10;
            // 
            // pbWizard
            // 
            this.pbWizard.Image = ((System.Drawing.Image)(resources.GetObject("pbWizard.Image")));
            this.pbWizard.Location = new System.Drawing.Point(10, 3);
            this.pbWizard.Name = "pbWizard";
            this.pbWizard.Size = new System.Drawing.Size(40, 32);
            this.pbWizard.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.pbWizard.TabIndex = 10;
            this.pbWizard.TabStop = false;
            // 
            // groupBox5
            // 
            this.groupBox5.Controls.Add(this.cbWsdlLocation);
            this.groupBox5.Controls.Add(this.bnBrowse);
            this.groupBox5.Controls.Add(this.label4);
            this.groupBox5.Location = new System.Drawing.Point(8, 48);
            this.groupBox5.Name = "groupBox5";
            this.groupBox5.Size = new System.Drawing.Size(553, 49);
            this.groupBox5.TabIndex = 11;
            this.groupBox5.TabStop = false;
            this.groupBox5.Text = "Contract information  ";
            // 
            // cbWsdlLocation
            // 
            this.cbWsdlLocation.Enabled = false;
            this.cbWsdlLocation.Location = new System.Drawing.Point(96, 18);
            this.cbWsdlLocation.MaxDropDownItems = 10;
            this.cbWsdlLocation.Name = "cbWsdlLocation";
            this.cbWsdlLocation.Size = new System.Drawing.Size(404, 21);
            this.cbWsdlLocation.TabIndex = 0;
            this.cbWsdlLocation.SelectedIndexChanged += new System.EventHandler(this.cbWsdlLocation_SelectedIndexChanged);
            this.cbWsdlLocation.MouseMove += new System.Windows.Forms.MouseEventHandler(this.cbWsdlLocation_MouseMove);
            this.cbWsdlLocation.TextChanged += new System.EventHandler(this.tbWSDLLocation_TextChanged);
            // 
            // bnBrowse
            // 
            this.bnBrowse.Location = new System.Drawing.Point(512, 17);
            this.bnBrowse.Name = "bnBrowse";
            this.bnBrowse.Size = new System.Drawing.Size(32, 23);
            this.bnBrowse.TabIndex = 1;
            this.bnBrowse.Text = "...";
            this.bnBrowse.Click += new System.EventHandler(this.bnBrowse_Click);
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(8, 21);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(87, 20);
            this.label4.TabIndex = 0;
            this.label4.Text = "WSDL location:";
            // 
            // openFileDialogWSDL
            // 
            this.openFileDialogWSDL.Filter = "WSDL files|*.wsdl|All Files|*.*";
            // 
            // groupBox6
            // 
            this.groupBox6.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.groupBox6.Controls.Add(this.cbEndpointConfig);
            this.groupBox6.Controls.Add(this.cbAccessSOAP);
            this.groupBox6.Controls.Add(this.rbClient);
            this.groupBox6.Location = new System.Drawing.Point(8, 15);
            this.groupBox6.Name = "groupBox6";
            this.groupBox6.Size = new System.Drawing.Size(272, 56);
            this.groupBox6.TabIndex = 7;
            this.groupBox6.TabStop = false;
            this.groupBox6.Text = "Client";
            // 
            // groupBox7
            // 
            this.groupBox7.Controls.Add(this.cbEnableWsdl);
            this.groupBox7.Controls.Add(this.cbValidate);
            this.groupBox7.Controls.Add(this.rbServer);
            this.groupBox7.Location = new System.Drawing.Point(288, 15);
            this.groupBox7.Name = "groupBox7";
            this.groupBox7.Size = new System.Drawing.Size(256, 56);
            this.groupBox7.TabIndex = 8;
            this.groupBox7.TabStop = false;
            this.groupBox7.Text = "Service";
            // 
            // groupBox1
            // 
            this.groupBox1.Anchor = System.Windows.Forms.AnchorStyles.None;
            this.groupBox1.Controls.Add(this.groupBox4);
            this.groupBox1.Controls.Add(this.groupBox7);
            this.groupBox1.Controls.Add(this.groupBox6);
            this.groupBox1.Location = new System.Drawing.Point(8, 104);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(553, 206);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Code generation  ";
            // 
            // groupBox4
            // 
            this.groupBox4.Controls.Add(this.cbXxxSpecified);
            this.groupBox4.Controls.Add(this.cbGenericList);
            this.groupBox4.Controls.Add(this.cbOldAsync);
            this.groupBox4.Controls.Add(this.cbDataBinding);
            this.groupBox4.Controls.Add(this.cbOrderIds);
            this.groupBox4.Controls.Add(this.cbCollections);
            this.groupBox4.Controls.Add(this.cbMultipleFiles);
            this.groupBox4.Controls.Add(this.cbProperties);
            this.groupBox4.Controls.Add(this.cbAdjustCasing);
            this.groupBox4.Controls.Add(this.cbSerializable);
            this.groupBox4.Location = new System.Drawing.Point(8, 77);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new System.Drawing.Size(536, 123);
            this.groupBox4.TabIndex = 11;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "Options  ";
            // 
            // WebServiceCodeGenDialogNew
            // 
            this.AcceptButton = this.button1;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.button2;
            this.ClientSize = new System.Drawing.Size(570, 443);
            this.Controls.Add(this.cbOverwrite);
            this.Controls.Add(this.groupBox5);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.cbSettings);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "WebServiceCodeGenDialogNew";
            this.Text = "WSCF Code Generation Options 0.7";
            this.Closed += new System.EventHandler(this.WebServiceCodeGenOptions_Closed);
            this.Load += new System.EventHandler(this.WebServiceCodeGenOptions_Load);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pbWscf)).EndInit();
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pbWizard)).EndInit();
            this.groupBox5.ResumeLayout(false);
            this.groupBox6.ResumeLayout(false);
            this.groupBox7.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            this.groupBox4.ResumeLayout(false);
            this.groupBox4.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, EventArgs e)
		{
			if(rbClient.Checked || rbServer.Checked)
			{
				if((tbNamespaceProxy.Text.Length == 0 && tbNamespaceProxy.Enabled == true) ||
					(tbNamespaceStub.Text.Length == 0 && tbNamespaceStub.Enabled == true) ||
					(tbProxyFile.Text.Length == 0 && tbProxyFile.Enabled == true) ||
					(tbStubFile.Text.Length == 0 && tbStubFile.Enabled == true) ||
                    (tbStubFile.Enabled == true && !ValidationHelper.IsWindowsFileName(tbStubFile.Text)) ||
                    (tbProxyFile.Enabled == true && !ValidationHelper.IsWindowsFileName(tbProxyFile.Text)) || 
                    (tbNamespaceStub.Enabled == true && !ValidationHelper.IsDotNetNamespace(tbNamespaceStub.Text)) ||
                    (tbNamespaceProxy.Enabled == true && !ValidationHelper.IsDotNetNamespace(tbNamespaceProxy.Text)) || 
					cbWsdlLocation.Text.Length == 0)
				{
					this.DialogResult = DialogResult.None;
					button1.DialogResult = DialogResult.None;

					MessageBox.Show("Sorry, please enter valid values.",
						"Web Services Contract-First code generation", MessageBoxButtons.OK,
									MessageBoxIcon.Exclamation);
				}
				else
				{
					this.DialogResult = DialogResult.OK;
					this.Close();
				}
			}
			else
			{
				this.DialogResult = DialogResult.None;
				button1.DialogResult = DialogResult.None;

				MessageBox.Show("Please choose code generation options.",
					"Web Services Contract-First code generation", MessageBoxButtons.OK,
					MessageBoxIcon.Exclamation);
			}
		}       

		private void WebServiceCodeGenOptions_Load(object sender, EventArgs e)
		{
			if(wsdlLocation.Length == 0)
			{
				cbWsdlLocation.Enabled = true;
				cbWsdlLocation.Focus();
			}
		
			if(!cbWsdlLocation.Enabled) bnBrowse.Enabled = false;
		
			LoadFormValues();

			if(rbClient.Checked || rbServer.Checked) button1.Enabled = true;
            isLoading = false;
		}

		private void cbClient_CheckedChanged(object sender, EventArgs e)
		{
            rbServer.Checked = !rbClient.Checked;
			button1.Enabled = rbClient.Checked;		
			cbAccessSOAP.Enabled = rbClient.Checked;			
			cbEndpointConfig.Enabled = rbClient.Checked;
			
			if(tbNamespaceProxy.Enabled == false)
				tbNamespaceProxy.Enabled = true;
			else
				tbNamespaceProxy.Enabled = false;
			if(tbProxyFile.Enabled == true)
				tbProxyFile.Enabled = false;
			else
				tbProxyFile.Enabled = true;
		}

		private void cbServer_CheckedChanged(object sender, EventArgs e)
		{
            rbClient.Checked = !rbServer.Checked;
			button1.Enabled = rbServer.Checked;						
			cbValidate.Enabled = rbServer.Checked;            
            cbEnableWsdl.Enabled = rbServer.Checked;

			if(tbNamespaceStub.Enabled == false)
				tbNamespaceStub.Enabled = true;
			else
				tbNamespaceStub.Enabled = false;
			if(tbStubFile.Enabled == true)
				tbStubFile.Enabled = false;
			else
				tbStubFile.Enabled = true;		
        }

		private void ttPicBox_Click(object sender, EventArgs e)
		{
			Process.Start("http://www.thinktecture.com/");
		}

		private void bnBrowse_Click(object sender, EventArgs e)
		{
			if(openFileDialogWSDL.ShowDialog() == DialogResult.OK)
			{
				// BDS: Commented this code.
				/*
				if(cbWsdlLocation.Items.Count >= 10)
				{
					cbWsdlLocation.Items.RemoveAt(0);
				}
				if(cbWsdlLocation.Items.IndexOf(openFileDialogWSDL.FileName) == -1)
				{
					cbWsdlLocation.Items.Add(openFileDialogWSDL.FileName);
					cbWsdlLocation.SelectedIndex = cbWsdlLocation.Items.Count - 1;
				}
				
				externalFile = true;
				*/

				// BDS: Added the following code to support the new wsdl file cache.
				AddWsdlFileToCache(openFileDialogWSDL.FileName);
			}
		}
		
		private void SaveFormValues()
		{
			ConfigurationManager config = ConfigurationManager.GetConfigurationManager("WSCF05");
			config.Write("ClientCode", rbClient.Checked.ToString());
			config.Write("Collections", cbCollections.Checked.ToString());
			config.Write("EndpointConfig", cbEndpointConfig.Checked.ToString());
			config.Write("Properties", cbProperties.Checked.ToString());
			config.Write("ProxyFile", tbProxyFile.Text);
			config.Write("NamespaceProxy", tbNamespaceProxy.Text);
			config.Write("Serializable", cbSerializable.Checked.ToString());
			config.Write("ServerCode", rbServer.Checked.ToString());
			config.Write("AccessSOAP", cbAccessSOAP.Checked.ToString());
			config.Write("StubFile", tbStubFile.Text);
			config.Write("NamespaceStub", tbNamespaceStub.Text);
			config.Write("Validate", cbValidate.Checked.ToString());
            config.Write("EnableWsdl", cbEnableWsdl.Checked.ToString());
            config.Write("AdjustCasing", cbAdjustCasing.Checked.ToString());            
            config.Write("OrderIdentifiers", cbOrderIds.Checked.ToString());
            config.Write("DataBinding", cbDataBinding.Checked.ToString());
            config.Write("OldAsync", cbOldAsync.Checked.ToString());
            config.Write("Overwrite", cbOverwrite.Checked.ToString());
            config.Write("GenericList", cbGenericList.Checked.ToString());
            config.Write("XxxSpecified", cbXxxSpecified.Checked.ToString());

			// BDS: Modified the code to store the values pasted to the combo box.
			if(cbWsdlLocation.SelectedItem != null)
			{
				config.Write("WSDLLocation", 
					wsdlFileCache[cbWsdlLocation.SelectedIndex].ToString());
				wsdlPath = wsdlFileCache[cbWsdlLocation.SelectedIndex].ToString();
			}
			else
			{
				config.Write("WSDLLocation", cbWsdlLocation.Text);
				wsdlPath = cbWsdlLocation.Text;
			}
			
			config.Write("RememberSettings", cbSettings.Checked.ToString());
			config.Write("MultipleFiles", cbMultipleFiles.Checked.ToString());
			
			string wsdlUrlsString = "";
			
			// Add the current item.
			if(cbWsdlLocation.SelectedItem == null)
			{
				string fname = AddWsdlFileToCache(cbWsdlLocation.Text);				
			}

			foreach(string path in wsdlFileCache)
			{
				wsdlUrlsString += path + ";";
			}

			config.Write("WsdlUrls", wsdlUrlsString);
			config.Persist();
		}

		private void LoadFormValues()
		{
			ConfigurationManager config = ConfigurationManager.GetConfigurationManager("WSCF05");			
			string wsdlUrls = config.Read("WsdlUrls");
			
			//if (wsdlUrls.Length > 0)
			//{
			cbWsdlLocation.Items.Clear();
			wsdlUrls = wsdlUrls.Trim(';');
			string[] urls = wsdlUrls.Split(';');
			
			// BDS: Changed this code to use new wsdl file cache.
			for(int urlIndex = 0; urlIndex < urls.Length; urlIndex++)
			{
				string fname = AddWsdlFileToCache(urls[urlIndex]);	
			}
			
			if(cbWsdlLocation.Items.Count > 0)
			{
				cbWsdlLocation.SelectedIndex = 0;
			}

			if(wsdlLocation.Length > 0)
			{
				if(!wsdlFileCache.Contains(wsdlLocation))
				{
					string fname = AddWsdlFileToCache(wsdlLocation);
				}
				else 
				{
					int wsdlIndex = wsdlFileCache.IndexOf(wsdlLocation);
					cbWsdlLocation.SelectedIndex = wsdlIndex;
				}
			}
			//}

			if (config.ReadBoolean("RememberSettings"))
			{
				cbSettings.Checked = config.ReadBoolean("RememberSettings");
				rbClient.Checked = config.ReadBoolean("ClientCode");
				cbCollections.Checked = config.ReadBoolean("Collections");
				cbEndpointConfig.Checked = config.ReadBoolean("EndpointConfig");
				cbProperties.Checked = config.ReadBoolean("Properties");
				tbProxyFile.Text = config.Read("ProxyFile");
				tbNamespaceProxy.Text = config.Read("NamespaceProxy");
				cbSerializable.Checked = config.ReadBoolean("Serializable");
				rbServer.Checked = config.ReadBoolean("ServerCode");
				cbAccessSOAP.Checked = config.ReadBoolean("AccessSOAP");
				tbStubFile.Text = config.Read("StubFile");
				tbNamespaceStub.Text = config.Read("NamespaceStub");
				cbValidate.Checked = config.ReadBoolean("Validate");
				cbMultipleFiles.Checked = config.ReadBoolean("MultipleFiles");
                cbEnableWsdl.Checked = config.ReadBoolean("EnableWsdl");
                cbAdjustCasing.Checked = config.ReadBoolean("AdjustCasing");
                cbOrderIds.Checked = config.ReadBoolean("OrderIdentifiers");
                cbDataBinding.Checked = config.ReadBoolean("DataBinding");
                cbOldAsync.Checked = config.ReadBoolean("OldAsync");
                cbOverwrite.Checked = config.ReadBoolean("Overwrite");
                cbGenericList.Checked = config.ReadBoolean("GenericList");
                cbXxxSpecified.Checked = config.ReadBoolean("XxxSpecified");
			}
		}

		private void ttPicBox_MouseEnter(object sender, EventArgs e)
		{
			Cursor.Current = Cursors.Hand;
		}

		private void ttPicBox_MouseLeave(object sender, EventArgs e)
		{
			Cursor.Current = Cursors.Default;
		}

		private void ttPicBox_MouseMove(object sender, MouseEventArgs e)
		{
			//if((e.X > ttPicBox.Location.X && e.X < ttPicBox.Location.X + ttPicBox.Width) &&
			//	(e.Y > ttPicBox.Location.Y && e.Y < ttPicBox.Location.Y + ttPicBox.Height))
			//{
			//	Cursor.Current = Cursors.Hand;
			//}
		}

		private void tbWSDLLocation_TextChanged(object sender, EventArgs e)
		{			
//			if(cbWsdlLocation.Items.IndexOf(openFileDialogWSDL.FileName) == -1)
//			{
//				if(cbWsdlLocation.Items.Count >= 10)
//				{
//					cbWsdlLocation.Items.RemoveAt(0);
//				}
//
//				cbWsdlLocation.Items.Add(openFileDialogWSDL.FileName);
//				cbWsdlLocation.SelectedIndex = cbWsdlLocation.Items.Count - 1;
//			}
//			
//			externalFile = true;
		}

		private void WebServiceCodeGenOptions_Closed(object sender, EventArgs e)
		{
			// BDS: Save the values only if the OK button is clicked.
			if(this.DialogResult == DialogResult.OK)
			{
				SaveFormValues();		
			}
		}

		private void cbWsdlLocation_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
		
		/// <summary>
		/// Disply the location of the WSDL when moving the mouse over the combo box.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">Event arguments.</param>
		private void cbWsdlLocation_MouseMove(object sender, MouseEventArgs e)
		{
			if(cbWsdlLocation.SelectedIndex >= 0)
			{
				cfTooltip.SetToolTip(cbWsdlLocation, 
					wsdlFileCache[cbWsdlLocation.SelectedIndex].ToString());		
			}
		}

		/// <summary>
		/// Adds a wsdl file info to the wsdl file cache.
		/// </summary>
		/// <param name="path">Path of the wsdl file to add.</param>
		/// <returns>A string indicating the name of the wsdl file.</returns>
		/// <author>BDS - thinktecture</author>
		private string AddWsdlFileToCache(string path)
		{
			if(path.LastIndexOf("\\") > 0 && path.ToLower().EndsWith(".wsdl"))
			{
				if(wsdlFileCache.Count == 10)
				{
					wsdlFileCache.RemoveAt(0);
					cbWsdlLocation.Items.RemoveAt(0);
				}
				string fname = path.Substring(path.LastIndexOf("\\") + 1);
				wsdlFileCache.Add(path);
				cbWsdlLocation.SelectedIndex = cbWsdlLocation.Items.Add(fname);
				return fname;
			}

			return "";
		}

		private string GetFileNameFromPath(string path)
		{
			string fname = "";
			if(path.LastIndexOf("\\") < path.Length - 1)
			{
				fname = path.Substring(path.LastIndexOf("\\") + 1);
			}
			return fname;
		}

		private void cbOverwrite_CheckedChanged(object sender, System.EventArgs e)
		{
            if (!isLoading)
            {
                if (cbOverwrite.Checked)
                {
                    if (MessageBox.Show(this,
                        "This will overwrite the existing files in the project. Are you sure you want to enable this option anyway?",
                        "Web Services Contract-First code generation",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        cbOverwrite.Checked = false;
                    }
                }
            }
		}

		private void pbWscf_Click(object sender, System.EventArgs e)
		{
			Process.Start("http://www.thinktecture.com/");
		}        

		public bool ServiceCode
		{
			get { return rbServer.Checked; }
		}

		public bool ClientCode
		{
			get { return rbClient.Checked; }
		}

		public string ProxyFilename
		{
			get { return tbProxyFile.Text; }
			set { tbProxyFile.Text = value; }
		}

		public string StubFilename
		{
			get { return tbStubFile.Text; }
			set { tbStubFile.Text = value; }
		}

		public string NamespaceProxy
		{
			get { return tbNamespaceProxy.Text; }
			set { tbNamespaceProxy.Text = value; }
		}

		public string NamespaceStub
		{
			get { return tbNamespaceStub.Text; }
			set { tbNamespaceStub.Text = value; }
		}

		public bool GenerateProperties
		{
			get { return cbProperties.Checked; }
		}

		public bool EndpointConfig
		{
			get { return cbEndpointConfig.Enabled && cbEndpointConfig.Checked; }
		}

		public bool AccessSoap
		{
			get { return cbAccessSOAP.Enabled && cbAccessSOAP.Checked; }
		}

		public bool EnableValidate
		{
			get { return cbValidate.Enabled && cbValidate.Checked; }
		}

		public bool SerializableClasses
		{
			get { return cbSerializable.Checked; }
		}

		public bool Collections
		{
			get { return cbCollections.Checked; }
		}

		public string WsdlLocation
		{
			get { return cbWsdlLocation.Text; }
			set	{ wsdlLocation = value; }
		}

		public bool ExternalFile
		{
			get { return externalFile; }
		}

		public bool GenerateMultipleFiles
		{
			get { return cbMultipleFiles.Checked; }
		}

		public string WsdlPath
		{
			get { return this.wsdlPath; }
		}

		public bool Overwrite
		{
			get { return this.cbOverwrite.Checked; }
		}

        public bool ChangeCasing
        {
            get { return this.cbAdjustCasing.Checked; }
        }

        public bool EnableWsdl
        {
            get 
            { 
                return cbEnableWsdl.Enabled && this.cbEnableWsdl.Checked; 
            }            
        }

        public bool EnableDataBinding
        {
            get { return this.cbDataBinding.Checked; }
        }

        public bool OrderIdentifiers
        {
            get { return this.cbOrderIds.Checked; }
        }

        public bool OldAsyncCode
        {
            get { return this.cbOldAsync.Checked; }
        }

        public bool NoXxxSpecifiedHandling
        {
            get { return this.cbXxxSpecified.Checked; }
        }

        public bool GenericList
        {
            get { return this.cbGenericList.Checked; }
        }

        private void cbDataBinding_CheckedChanged(object sender, EventArgs e)
        {
            if (!cbProperties.Checked)
            {
                cbProperties.Checked = true;
                cbProperties.CheckState = CheckState.Indeterminate;
                cbProperties.Enabled = false;
            }
            else
            {
                if (cbProperties.Checked && 
                    cbProperties.CheckState == CheckState.Indeterminate)
                {
                    cbProperties.Checked = false;
                }
                cbProperties.Enabled = true;
            }
        }

        private void cbSettings_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void cbCollections_CheckedChanged(object sender, EventArgs e)
        {
            if (cbGenericList.Checked)
            {
                cbGenericList.Checked = !cbCollections.Checked;
            }
        }

        private void cbGenericList_CheckedChanged(object sender, EventArgs e)
        {
            if (cbCollections.Checked)
            {
                cbCollections.Checked = !cbGenericList.Checked;
            }
        }
	}
}
